package com.weishi.project.training.controller;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.TrainingGroup;
import com.weishi.project.training.service.ITrainingGroupService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * 训练小组Controller
 */
@Api(value = "训练小组",description = "训练小组")
@RestController
@RequestMapping("/trainingGroup/trainingGroup")
public class TrainingGroupController extends BaseController {

    @Autowired
    private ITrainingGroupService trainingGroupService;

    /**
     * 查询训练小组列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TrainingGroup trainingGroup) {
        startPage();
        List<TrainingGroup> list = trainingGroupService.selectTrainingGroupList1(trainingGroup);
        return getDataTable(list);
    }

    /**
     * 导出训练小组列表
     */
    @Log(title = "训练小组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TrainingGroup trainingGroup) {
        List<TrainingGroup> list = trainingGroupService.selectTrainingGroupList(trainingGroup);
        ExcelUtil<TrainingGroup> util = new ExcelUtil<TrainingGroup>(TrainingGroup.class);
        return util.exportExcel(list, "trainingGroup");
    }

    /**
     * 获取训练小组详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(trainingGroupService.getById(id));
    }

    /**
     * 新增训练小组
     */
    @Log(title = "训练小组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingGroup trainingGroup) {
        trainingGroup.setCtime(new Date());
        trainingGroupService.save(trainingGroup);
        return AjaxResult.success();
    }

    /**
     * 修改训练小组
     */
    @Log(title = "训练小组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingGroup trainingGroup) {
        trainingGroupService.updateById(trainingGroup);
        return AjaxResult.success();
    }

    /**
     * 删除训练小组
     */
    @PreAuthorize("@ss.hasPermi('trainingGroup:trainingGroup:remove')")
    @Log(title = "训练小组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        trainingGroupService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 获取小组名称集合
     */
    @GetMapping("/getGroupNameList")
    public TableDataInfo getGroupNameList(TrainingGroup trainingGroup) {
        startPage();
        List<TrainingGroup> list = trainingGroupService.getGroupNameList();
        return getDataTable(list);
    }

}